package Demo2;

public class Demo2 {
    //public static boolean flag = true;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
           while(!Thread.currentThread().isInterrupted()) {
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   //throw new RuntimeException(e);
                   System.out.println("thread 结束了");
                   break;
               }
           }
        });

        t.start();
        Thread.sleep(3000);
        t.interrupt();
        //flag = false;
        System.out.println("hello main");
    }
}
